package com.zh.wl;



import com.aliyun.oss.ServiceException;
import org.junit.jupiter.api.Test;

import java.rmi.RemoteException;

/**
 * 在线订单模块测试
 * 本次测试未使用cfx框架对webservice进行交互,后续开发应使用框架进行开发,提高效率!spring+idea+maven+cfx协作开发服务端
 * 利用wbservice技术获取客户提供的wsdl接口,书写客户端代码进行调用webservice写好的逻辑进行交互
 */
public class Wlendent {
    /**
     * 根据传入的 ReferenceNumber 引用单号，可以是客户单号或服务商单号查询订单信息
     *
     * @throws RemoteException
     * @throws ServiceException
     */
    @Test
    public void findOrder() throws RemoteException, ServiceException, javax.xml.rpc.ServiceException {
        OrderOnlineServiceExtImplServiceLocator serviceLocator = new OrderOnlineServiceExtImplServiceLocator();
        IOrderOnlineService service = serviceLocator.getOrderOnlineServiceExtImplPort();
        FindOrderRequest findOrderRequest = new FindOrderRequest();
        String str[] = {"102", "103"};
        findOrderRequest.setOrderNo(str);
        FindOrderResponse findOrderResponse = service.findOrderService(null, findOrderRequest);
        System.out.println(findOrderResponse.hashCode() + "+" + findOrderResponse.getOrderItem());
    }

    /**
     * 创建订单需要将订单全部信息上传交给webservice服务端进行逻辑上的处理
     *
     * @throws ServiceException
     * @throws RemoteException
     */
    @Test
    public void creatOrder() throws ServiceException, RemoteException, javax.xml.rpc.ServiceException {
        OrderOnlineServiceExtImplServiceLocator serviceLocator = new OrderOnlineServiceExtImplServiceLocator();
        IOrderOnlineService service = serviceLocator.getOrderOnlineServiceExtImplPort();
        CreateOrderRequest[] createOrderRequests = new CreateOrderRequest[2];
        createOrderRequests[0] = new CreateOrderRequest();
        createOrderRequests[0].setOrderNo("10021231333");
        createOrderRequests[0].setTrackingNumber("123");
        createOrderRequests[0].setPaymentCode("1003");
        createOrderRequests[0].setCargoCode("P");
        createOrderRequests[0].setPaymentCode("P");
        createOrderRequests[0].setInitialCountryCode("CN");
        createOrderRequests[0].setDestinationCountryCode("RU");
        createOrderRequests[0].setPieces("2");
        createOrderRequests[0].setInsurType("8Y");
        createOrderRequests[0].setInsurValue("8");
        createOrderRequests[0].setBuyerId("2333");
        createOrderRequests[0].setReturnSign("N");
        createOrderRequests[0].setCustomerWeight("5");
        createOrderRequests[0].setTransactionId("123456");
        createOrderRequests[0].setShipperCompanyName("百盛");
        createOrderRequests[0].setShipperName("张三");
        createOrderRequests[0].setShipperStateOrProvince("广东");
        createOrderRequests[0].setShipperCity("广州");
        createOrderRequests[0].setShipperAddress("科技路");
        createOrderRequests[0].setConsigneeName("王五");
        createOrderRequests[0].setStreet("大庆路");
        createOrderRequests[0].setCity("西安");
        createOrderRequests[0].setStateOrProvince("陕西");
        createOrderRequests[0].setProductCode("AO");
        createOrderRequests[0].setConsigneePostCode("");
        String Token = "A96A6ECEA7E103BA0EA877B69D28A833";
        CreateOrderResponse[] createOrderResponses = service.createOrderService(Token, createOrderRequests);
        System.out.println(createOrderResponses[0].getAck());
        System.out.println(createOrderResponses[0].getErrors());
        System.out.println(createOrderResponses.length);
    }

    /**
     * 修改订单只需要将有修改的信息上传,服务端自行处理
     */
    @Test
    public void modifOrder() {
        OrderOnlineServiceExtImplServiceLocator orderOnlineServiceExtImplServiceLocator = new OrderOnlineServiceExtImplServiceLocator();
        IOrderOnlineService service = null;
        try {
            service = orderOnlineServiceExtImplServiceLocator.getOrderOnlineServiceExtImplPort();
            ModifyOrderRequest[] modifyOrderRequest = null;
            try {
                ModifyOrderResponse[] modifyOrderResponses = service.modifyOrderService(null, modifyOrderRequest);
                for (int i = 1; i < modifyOrderResponses.length; i++) {
                    System.out.println(modifyOrderRequest[i]);
                }
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (javax.xml.rpc.ServiceException e) {
            e.printStackTrace();
        }

    }

    /**
     * 删除订单需要订单编号多个或者一个
     */
    @Test
    public void removeOrder() {
        OrderOnlineServiceExtImplServiceLocator serviceLocator = new OrderOnlineServiceExtImplServiceLocator();
        try {
            IOrderOnlineService service = serviceLocator.getOrderOnlineServiceExtImplPort();
            String[] strings = {"102"};
            RemoveOrderResponse[] removeOrderResponses = service.removeOrderService(null, strings);
            System.out.println(removeOrderResponses.length);
            System.out.println(removeOrderResponses[0].getReferenceNumber());
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (javax.xml.rpc.ServiceException e) {
            e.printStackTrace();
        }
    }

    /**
     * 预订单目前还没搞懂0.0
     */
    @Test
    public void preAlertOrder() {
        OrderOnlineServiceExtImplServiceLocator serviceLocator = new OrderOnlineServiceExtImplServiceLocator();
        try {
            IOrderOnlineService service = serviceLocator.getOrderOnlineServiceExtImplPort();
            String[] strings = {"102"};
            String arg0 = "A96A6ECEA7E103BA0EA877B69D28A833";
            PreAlertOrderResponse[] preAlertOrderResponses = service.preAlertOrderService(arg0, strings);
            System.out.println(preAlertOrderResponses.length);
            System.out.println(preAlertOrderResponses[0].getTimestamp() + "\n" + preAlertOrderResponses[0].getAck());
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (javax.xml.rpc.ServiceException e) {
            e.printStackTrace();
        }
    }
}
